home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / COMMUNIC / H399.ZIP / ODY200SH.LZH / BIG.SCR next >
Text File  |  1989-09-15  |  9KB  |  283 lines

  1.  
  2. /* This file is here to serve as a more substantial example of an Odyssey
  3.    script. It is probably not directly useful to you unless you use the UK
  4.    CIX system in association with a PD offline reader program called Query.
  5. */
  6.  
  7. SCRIPT getcix;
  8.  
  9. VAR mailw,nomsgs,MailPrompt,MainPrompt,ReadPrompt,SubSystem:Number;
  10.     GotMail,GotMessages:Flag;
  11.     f:File;
  12.     Conf,Msgno,Line:String;
  13.  
  14. /*.............................................*/
  15.  
  16. Func Login():Flag;
  17.  
  18. Var ReDials:Number;
  19.     CIXok:Flag;
  20.     Id,Password:String;
  21.  
  22. Begin
  23.      ClrScr();
  24.      Write("█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█|");
  25.      Write("█        Calling CIX via Direct Dial        █|");
  26.      Write("█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█|");
  27.      IF FetchStr("CIX",Id,Password) THEN
  28.          ReDials:=0; CIXok:=FALSE;
  29.          REPEAT
  30.                CASE Redials % 3 OF
  31.                     0:IF Dial("CIX1") THEN CIXok:=TRUE; END;
  32.                  |  1:IF Dial("CIX2") THEN CIXok:=TRUE; END;
  33.                  |  2:IF Dial("CIX3") THEN CIXok:=TRUE; END;
  34.                END;
  35.                IF CIXok THEN
  36.                    IF WaitFor("login:",10) THEN
  37.                        Paste("qix");
  38.                      ELSE
  39.                        HangUp(); CIXok:=FALSE;
  40.                    END;
  41.                END;
  42.                IF NOT CIXok THEN
  43.                    INC(Redials);
  44.                    IF Redials=10 THEN
  45.                        Write("Could not connect to CIX|");
  46.                        RETURN FALSE;
  47.                    END;
  48.                    Delay(5);
  49.                END;
  50.          UNTIL CIXok;
  51.          WaitFor("user) ");    Transmit(Id);
  52.          WaitFor("Password:"); Transmit(Password);
  53.          RETURN TRUE;
  54.        ELSE
  55.          Write("|Failed to find Id and Password.|");
  56.          RETURN FALSE;
  57.      END;
  58. End; /* Login */
  59.  
  60. /*.............................................*/
  61.  
  62. Proc ChangeSubSystem(sys:Number);
  63. Begin
  64.      IF SubSystem<>sys THEN
  65.          IF SubSystem<>MainPrompt THEN Paste("q"); WaitFor("Main:"); END;
  66.          IF sys=MailPrompt THEN
  67.              Paste("mail"); WaitFor("Mail:"); Delay(1);
  68.          END;
  69.          SubSystem := sys;
  70.      END;
  71. End; /* ChangeSubSystem */
  72.  
  73. /*.............................................*/
  74.  
  75. Proc SendMail();
  76. Begin
  77.      ChangeSubSystem(MailPrompt);
  78.      IF FEOF(f) THEN RETURN; END;
  79.      Paste("to "+line); WaitFor("Enter subject: ");
  80.      FRead(f,line);
  81.      IF Pos("SUBJECT:",line)=0 THEN
  82.          Paste(SubStr(line,8,80));
  83.          WaitFor(".<CR>");
  84.        ELSE
  85.          Paste(""); WaitFor(".<CR>"); WaitFor(">",4); Paste(line);
  86.      END;
  87.      WHILE NOT FEOF(f) DO
  88.          WaitFor(">",4);
  89.          FRead(f,line); Paste(line);
  90.          IF line="." THEN
  91.              WaitFor("send/action:"); Paste("send");
  92.              WaitFor("Mail:");
  93.              RETURN;
  94.          END;
  95.      END;
  96. End; /* SendMail */
  97.  
  98. /*.............................................*/
  99.  
  100. Proc AddMessage();
  101. Begin
  102.      WaitFor("Add/action:"); Paste("a");
  103.      WaitFor("Read:");
  104. End; /* AddMessage */
  105.  
  106. /*.............................................*/
  107.  
  108. Proc SendComment();
  109. Begin
  110.      ChangeSubSystem(ReadPrompt);
  111.      Paste("join "+Conf); WaitFor("Read:");
  112.      Paste("hea "+Msgno+" com");
  113.      WaitFor(".<CR>");
  114.      WHILE NOT FEOF(f) DO
  115.          WaitFor(">",4);
  116.          FRead(f,line); Paste(line);
  117.          IF line="." THEN AddMessage(); RETURN; END;
  118.      END;
  119. End; /* SendComment */
  120.  
  121. /*.............................................*/
  122.  
  123. Proc SayMessage();
  124. Begin
  125.      ChangeSubSystem(ReadPrompt);
  126.      IF FEOF(f) THEN RETURN; END;
  127.      Paste("join "+Conf); WaitFor("Read:");
  128.      Paste("say"); WaitFor("TITLE:");
  129.      FRead(f,line);
  130.      IF Pos("TITLE:",line)=0 THEN
  131.          Paste(SubStr(line,6,80));
  132.          WaitFor(".<CR>");
  133.        ELSE
  134.          Paste(""); WaitFor(".<CR>"); WaitFor(">",4); Paste(line);
  135.      END;
  136.      WHILE NOT FEOF(f) DO
  137.          WaitFor(">",4);
  138.          FRead(f,line); Paste(line);
  139.          IF line="." THEN AddMessage(); RETURN; END;
  140.      END;
  141. End; /* SayMessage */
  142.  
  143. /*.............................................*/
  144.  
  145. Proc CheckReply();
  146.  
  147. Var MsgCount:Number;
  148.  
  149. Begin
  150.      MsgCount:=0;
  151.      IF IsFile("REPLY.BSC") THEN
  152.          FOpen(f,"REPLY.BSC");
  153.          FRead(f,line);
  154.          IF line<>"#begin" THEN
  155.              Write("REPLY.BSC not a valid reply file|");
  156.              FClose(f);
  157.              RETURN;
  158.          END;
  159.          WHILE NOT FEOF(f) DO
  160.              IF NOT OnLine() THEN
  161.                  Write("Line lost after ",MsgCount," messages were|");
  162.                  Write("successfully uploaded.|");
  163.                  Exit();
  164.              END;
  165.              FRead(f,line);
  166.              IF Pos("#m|",line)=0 THEN (* a mail message *)
  167.                  (* line has typical format: #m|cixid *)
  168.                  line := SubStr(line,3,80);
  169.                  SendMail();
  170.                ELSIF Pos("#c|",line)=0 THEN (* a comment *)
  171.                  (* line has typical format: #c|conf/topic|1234 *)
  172.                  line := SubStr(line,3,80);
  173.                  conf := SubStr(line,0,Pos("|",line));
  174.                  msgno := SubStr(line,Length(conf)+1,5);
  175.                  SendComment();
  176.                ELSIF Pos("#s|",line)=0 THEN (* say, ie originate a message *)
  177.                  (* line has typical format: #s|conf/topic *)
  178.                  conf := SubStr(line,3,80);
  179.                  SayMessage();
  180.                ELSIF Pos("#e|",line)=0 THEN (* end of message *)
  181.                  (* line has typical format: #e|1234 *)
  182.                  INC(MsgCount);
  183.                  msgno := SubStr(line,3,80);
  184.                  Paste("hea sk to "+msgno); WaitFor("Read:");
  185.                ELSIF Pos("#end",line)=0 THEN (* end of command file *)
  186.                  FClose(f);
  187.                  ChangeSubSystem(MainPrompt);
  188.                  FDelete("REPLY.BSC");
  189.                  RETURN; /* success */
  190.                ELSIF Pos("#r|",line)=0 THEN (* resign from a conf/topic *)
  191.                  (* line has typical format: #r|conf/topic *)
  192.                  ChangeSubSystem(MainPrompt);
  193.                  Paste("resign "+SubStr(line,3,80));
  194.                  WaitFor("Main:");
  195.                ELSIF Pos("#f|",line)=0 THEN  (* fixup CIX message pointers *)
  196.                  (* line has typical format: #f|conf/topic|1234 *)
  197.                  line := SubStr(line,3,80);
  198.                  conf := SubStr(line,0,Pos("|",line));
  199.                  msgno := SubStr(line,Length(conf)+1,5);
  200.                  Paste("join "+Conf); WaitFor("Read:");
  201.                  Paste("sk to "+Msgno); WaitFor("Read:");
  202.                ELSE
  203.                  Write("?? Error in REPLY.BSC format.|");
  204.                  FClose(f);
  205.                  ChangeSubSystem(MainPrompt);
  206.                  RETURN;
  207.              End;
  208.          End;
  209.          Write("Unexpected end of REPLY.BSC file.|");
  210.          FClose(f);
  211.          ChangeSubSystem(MainPrompt);
  212.          FDelete("REPLY.BSC");
  213.      END;
  214. End; /* CheckReply */
  215.  
  216. /*.............................................*/
  217.  
  218. Proc CheckMessages();
  219. Begin
  220.      IF GotMessages THEN
  221.          /* if there are messages then download them */
  222.          ChangeSubSystem(MainPrompt);
  223.          Delay(1);
  224.          Paste("file read all");
  225.          WaitFor("Main:"); Delay(1);
  226.      END;
  227. End; /* CheckMessages */
  228.  
  229. /*.............................................*/
  230.  
  231. Proc CheckMail();
  232. Begin
  233.      IF GotMail THEN
  234.          ChangeSubSystem(MailPrompt);
  235.          Paste("file all");
  236.          WaitFor("No new messages waiting");
  237.          WaitFor("Mail:");
  238.          Delay(1);
  239.          Paste("Clear inbask quick"); WaitFor("Mail:");
  240.          Paste("Clear outbask quick"); WaitFor("Mail:");
  241.      END;
  242. End; /* CheckMail */
  243.  
  244. /*.............................................*/
  245.  
  246. Proc DoDownload();
  247. Begin
  248.      IF GotMessages OR GotMail THEN
  249.          Paste("opt down z, q"); WaitFor("Main:");
  250.          Paste("download");
  251.          WaitFor("OK to delete"); Delay(2); Paste("");
  252.          WaitFor("Main:");
  253.      END;
  254. End; /* DoDownload */
  255.  
  256. /*.............................................*/
  257.  
  258. BEGIN
  259.      IF Login() THEN
  260.          mailw  := WatchFor("unread mail");
  261.          nomsgs := WatchFor("No new messages.");
  262.          When("More ?","|");
  263.          WaitFor("Main:");
  264.          GotMail := Received(mailw);
  265.          GotMessages := NOT Received(nomsgs);
  266.          ClrWatch(mailw);
  267.          ClrWatch(nomsgs);
  268.          Paste("opt term pagelength 0 q");
  269.          WaitFor("Main:");
  270.          MainPrompt:=0; ReadPrompt:=1; MailPrompt:=2;
  271.          SubSystem := MainPrompt;
  272.          CheckReply();
  273.          CheckMessages();
  274.          CheckMail();
  275.          ChangeSubSystem(MainPrompt);
  276.          DoDownload();
  277.          Delay(1);
  278.          Paste("bye");
  279.          WaitFor("Goodbye",5);
  280.          Halt();
  281.      END;
  282. END;
  283.